﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

namespace Fis.Win.Utils
{
    public class AppSession
    {
        static AppSession()
        {
            Book = TempBook;
        }

        public static Hashtable CreateServiceParamter(Hashtable model)
        {
            Hashtable p = new Hashtable(model);
            p["book"] = Agile.Engine.Utils.StringUtils.ToJson(Book);
            return p;
        }


        public static Hashtable Book { get; set; }
        public static Hashtable UserInfo { get; set; }

        public static Agile.Engine.View.IViewProvider GetViewProvider(string alias)
        {
            return Agile.Engine.ObjectContext.GetObject(alias) as Agile.Engine.View.IViewProvider;
        }

        /// <summary>
        /// 测试用临时帐号
        /// </summary>
        public static Hashtable TempBook
        {
            get
            {
                var m = new Hashtable();
                m["FACCLEVEL"] = 5;
                m["FACCSTRUCT"] = "4-2-2";
                m["FACCSYSTEM"] = "0";
                m["FBOOKSTARTIME"] = "0";
                m["FNAME"] = "测试账套";
                m["FBOOKRANGE"] = 5;
                m["FBOOKSTART"] = DateTime.Parse("2011-5-1");
                m["FBOOKINITIALIZED"] = 0;
                m["FBILLTYPE"] = "1";
                return m;
            }
        }

        public static bool IsComplateInitialize
        {
            get { return int.Parse(Book["FBOOKINITIALIZED"].ToString()) == 1; }
        }

        private static DataTable KeyValueData(params object[] args)
        {
            var d = new DataTable();
            d.Columns.Add("value");
            d.Columns.Add("display");

            foreach (var i in args)
                d.Rows.Add(i as object[]);
            return d;
        }

        public static DataTable StateCache()
        {
            var yesno = new object[]{
                new object[]{-1,"冻结"},
                new object[]{0, "未审核"},
                new object[]{1, "已审核"}
            };
            return KeyValueData(yesno);
        }

        public static DataTable RightsCache()
        {
            var yesno = new object[]{
                new object[]{0, "操作员"},
                new object[]{1, "主管"}
            };
            return KeyValueData(yesno);
        }

        public static DataTable CustomKindCache()
        {
            var yesno = new object[]{
                new object[]{0, "个人"},
                new object[]{1, "企业"}
            };
            return KeyValueData(yesno);
          
        }
    }
}
